﻿using System;

namespace BostonAzureSite.ViewHelpers
{
    public class MicroformatMarkupBuilder : ISemanticMarkupBuilder
    {
        // TODO: semantic markup builders should be an independent library

        const string MicroformatMarkupTemplate = 
            "<span class=\"dtstart\">" +
               "<abbr class=\"value\" title=\"{0}\">{1} </abbr>" +
            "</span>";

        /// <summary>
        /// Convert UTC date/time into semantic HTML markup for the provided LOCAL timezone 
        /// </summary>
        /// <param name="dateTimeUtc">Expecting date/time as UTC</param>
        /// <param name="targetTimeZone">dateTimeUtc is converted from UTC to this time zone</param>
        /// <returns>Semantic HTML snippet based on Microformat conventions</returns>
        public string GetSemanticMarkupForTimeZone(DateTime dateTimeUtc, TimeZoneInfo targetTimeZone)
        {
            DateTime localTime = TimeZoneTranslator.GetLocalTimeFromUtcTime(dateTimeUtc, targetTimeZone);
            var localTimeIso8601DateTimeString = String.Format("{0:o}", localTime);
            var localTimeEnglishDateTimeString = String.Format("{0:f}", localTime);
            
            var semanticHtml = String.Format(
                MicroformatMarkupTemplate, 
                localTimeIso8601DateTimeString, 
                localTimeEnglishDateTimeString);
            return semanticHtml;
        }
    }
}
